<?php
/**
 * Created by PhpStorm.
 *
 * Author : Traveler.
 * Time   : 2020/2/19 19:14
 * Company: Inner Mongolia Zhengzhi Network Technology Co., Ltd
 */

namespace app\admin\model;


use app\admin\BaseModel;

class IcafeCate extends BaseModel
{
    /**
     * 数据表名称
     * @var string
     */
    protected $table = 'ibms_icafe_cate';

    /**
     * 查询字段
     * @var array
     */
    protected $query = [
        'id'     => '=',
        'name'   => 'like',
        'status' => '=',
    ];

    /**
     * (静态)获取表格渲染数据
     * @param array $param     请求参数
     * @param bool  $isdeleted 删除标记
     * @return array
     */
    public static function getIcafeCateTable(array $param = [], bool $isdeleted = false)
    {
        $model  = new static;
        $where  = [['delete_time', $isdeleted ? '>' : '=', 0]];
        $filter = $model->filterParam($param, $where);

        return [
            'data'  => $model->where($filter['where'])->order('id')->page($filter['page'], $filter['limit'])->select(),
            'count' => $model->where($filter['where'])->count()
        ];
    }

    /**
     * (静态)获取所有有效的场所类型
     * @return \think\Collection
     */
    public static function getValidIcafeCate()
    {
        $where   = ['status' => 1, 'delete_time' => 0];
        $visible = ['id', 'name', 'bgcolor'];

        return static::where($where)->visible($visible)->select();
    }
}